package com.vipboot.aot.autoconfig;

import com.baomidou.mybatisplus.annotation.IEnum;
import com.baomidou.mybatisplus.core.MybatisParameterHandler;
import com.baomidou.mybatisplus.core.MybatisXMLLanguageDriver;
import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.handlers.CompositeEnumTypeHandler;
import com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandler;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import com.baomidou.mybatisplus.extension.handlers.GsonTypeHandler;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;

public class MyBaitsPlusRuntimeHintsRegistrar implements RuntimeHintsRegistrar {
    @Override
    public void registerHints(RuntimeHints hints, ClassLoader classLoader) {

        // TODO 增加了MybatisXMLLanguageDriver.class  MybatisSqlSessionFactoryBean.class
        hints.reflection().registerType(MybatisXMLLanguageDriver.class, MemberCategory.values());
        hints.reflection().registerType(MybatisSqlSessionFactoryBean.class, MemberCategory.values());

        hints.serialization().registerType(SerializedLambda.class);
        hints.reflection().registerType(SerializedLambda.class);

        hints.serialization().registerType(SFunction.class);
        hints.reflection().registerType(SFunction.class);

        hints.reflection().registerType(MybatisPlusInterceptor.class);
        hints.reflection().registerType(AbstractWrapper.class, MemberCategory.values());
        hints.reflection().registerType(LambdaQueryWrapper.class, MemberCategory.values());
        hints.reflection().registerType(LambdaUpdateWrapper.class, MemberCategory.values());
        hints.reflection().registerType(UpdateWrapper.class, MemberCategory.values());
        hints.reflection().registerType(QueryWrapper.class, MemberCategory.values());

        hints.reflection().registerType(MybatisParameterHandler.class, MemberCategory.DECLARED_FIELDS);
        hints.reflection().registerType(IEnum.class, MemberCategory.INVOKE_PUBLIC_METHODS);
        // register typeHandler
        hints.reflection().registerType(CompositeEnumTypeHandler.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
        hints.reflection().registerType(FastjsonTypeHandler.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
        hints.reflection().registerType(GsonTypeHandler.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
        hints.reflection().registerType(JacksonTypeHandler.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
        hints.reflection().registerType(MybatisEnumTypeHandler.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);

    }
}
